<?php

class DataBase {
    private $type = "localhost";
    private $user = "root";
    private $pass = "";
    private $name_db = "new_htbet";
    private $link;
    //Подключение к БД
    private function connect(){
        $this->link = mysql_connect($this->type, $this->user, $this->pass);
        mysql_select_db($this->name_db);
        mysql_query('SET NAMES "utf8"');
    }
    //Закрытие базы данных
    private function close(){
    	mysql_close($this->link);
    }
    //Получения существования пользователя.
    public function GetUser($login,$pass){
    	$this->connect();
    	$p = md5($pass);
    	$result = mysql_query("SELECT * FROM `users` WHERE `nick` = '$login' AND `password` = '$p'");
    	$num = mysql_num_rows($result);
    	$arr = mysql_fetch_assoc($result);
    	if($num==1&&$arr['status']=='1'){
    		return true;
    	}else{
    		return false;
    	}    	
    	$this->close();
    }
    //Получение списка всех языков
    public function AllLang(){
    	$this->connect();
    	$result = mysql_query("SELECT * FROM  `languages`");
    	$num = mysql_num_rows($result);
    	for($i=0;$i<$num;$i++){
    		$res[$i] = mysql_fetch_assoc($result);
    	}
    	$this->close();
    	return $res;
    }
    //Загрузка перевода нужной страницы
    public function LoadText($page){
    	$this->connect();
    	$result = mysql_query("SELECT * FROM `text` WHERE `page`= '$page' AND `id_lang` =".$_SESSION['lang']);
    	$num = mysql_num_rows($result);
    	for($i=0;$i<$num;$i++){
    		$res = mysql_fetch_assoc($result);
    		$ret[$res['index']] = $res['text'];
    	}
    	$this->close();
    	return $ret;
    }
	//Получения существования пользователя.
    public function issetUser($login){
    	$this->connect();
    	$result = mysql_query("SELECT `nick` FROM `users` WHERE `nick` = '$login'");
    	$num = mysql_num_rows($result);
     	if($num==1){
    		return true;
    	}else{
    		return false;
    	}    	
    	$this->close();
    }
    //Вставка нового пользователя
    function inserUser($login,$pass,$mail,$uniq_id){
    	$this->connect();
    	$result = @mysql_query("INSERT INTO `new_htbet`.`users` (`id`, `nick`, `password`, `email`, `uniq_id`, `status`, `param_status`, `country_id`, `language_id`, `ht_team`, `ht_country_id`, `ht_league_rang`, `ht_league_num`, `last_date`, `last_time`, `reg_ip`, `last_ip`, `date`, `last_konkurs`, `admin`, `moder`, `translate`, `translate_language`) VALUES (NULL, '$login', '$pass', '$mail', '$uniq_id', '0', '', '', '', '', '', '', '', '', '', '$_SERVER[REMOTE_ADDR]', '', NOW(), '', '', '', '', '');");
    	$this->close();
    	if($result)
    		return true;
    	return false;
    }
}
?>
